package com.advertisementsystem.Controller;

import com.advertisementsystem.Exception.ResponseResult;
import com.advertisementsystem.Servie.SysLogService;
import com.advertisementsystem.entity.SysLoginLog;
import com.advertisementsystem.entity.SysOperationLog;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/system/log")
public class SysLogController {

    @Autowired
    private SysLogService logService;

    @GetMapping("/operation")
    public ResponseResult<Page<SysOperationLog>> operationLogList(SysOperationLog operLog,
                                                                  @RequestParam(defaultValue = "1") long current,
                                                                  @RequestParam(defaultValue = "10") long size) {
        Page<SysOperationLog> page = new Page<>(current, size);
        return ResponseResult.success(logService.getOperationLogList(operLog, page));
    }

    @GetMapping("/login")
    public ResponseResult<Page<SysLoginLog>>loginLogList(SysLoginLog loginLog,
                                                         @RequestParam(defaultValue = "1") long current,
                                                         @RequestParam(defaultValue = "10") long size) {
        Page<SysLoginLog> page = new Page<>(current, size);
        return ResponseResult.success(logService.getLoginLogList(loginLog, page));
    }

    @DeleteMapping("/operation/{ids}")
    public ResponseResult deleteOperationLog(@PathVariable String ids) {
        logService.deleteOperationLogByIds(ids);
        return ResponseResult.success();
    }

    @DeleteMapping("/login/{ids}")
    public ResponseResult deleteLoginLog(@PathVariable String ids) {
        logService.deleteLoginLogByIds(ids);
        return ResponseResult.success();
    }

    @DeleteMapping("/operation/clean")
    public ResponseResult cleanOperationLog() {
        logService.cleanOperationLog();
        return ResponseResult.success();
    }

    @DeleteMapping("/login/clean")
    public ResponseResult cleanLoginLog() {
        logService.cleanLoginLog();
        return ResponseResult.success();
    }
}